home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 August / Macworld (1999-08).dmg / Shareware World / Info / For Developers / MADE 1.4.0 / User / User Functions.c < prev    next >
Text File  |  1999-05-26  |  6KB  |  246 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /*                                                                   */
  3. /*        MADE - Macintosh Application Development Essentials        */
  4. /*        ---------------------------------------------------        */
  5. /*           (c) Sig Software, http://www.sigsoftware.com/           */
  6. /*                                                                   */
  7. /* These files can only be used for experimental purposes. To obtain */
  8. /* fully commented code, source code for the functions in Essential  */
  9. /*   Extras.h and permission for usage in final projects, you must   */
  10. /*    purchase a license. See documentation for more information.    */
  11. /*                                                                   */
  12. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  13. /*                                                                   */
  14. /*  User Functions.c                                                 */
  15. /*  ----------------                                                 */
  16. /*                                                                   */
  17. /*  Off the shelf responses to replace with your code.               */
  18. /*                                                                   */
  19. /*  Version 1.0.0 - 10th November 1996                               */
  20. /*  Version 1.1.0 - 29th January 1998 - Modeless dialog support      */
  21. /*  Version 1.2.0 - 20th November 1998 - Changed example code        */
  22. /*  Version 1.4.0 - 26th May 1999 - Apple item, threading support    */
  23. /*                                                                   */
  24. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  25.  
  26. #include "Essential Headers.h"
  27. #include "Essential Prototypes.h"
  28.  
  29. enum {
  30.     AppleStart=128*65536,
  31.     AppleAbout,
  32.     
  33.     FileStart=129*65536,
  34.     FileNew,
  35.     FileOpen,
  36.     FileSep1,
  37.     FileClose,
  38.     FileSave,
  39.     FileSaveAs,
  40.     FileSep2,
  41.     FilePageSetup,
  42.     FilePrint,
  43.     FileSep3,
  44.     FileQuit,
  45.     
  46.     EditStart=130*65536,
  47.     EditUndo,
  48.     EditSep1,
  49.     EditCut,
  50.     EditCopy,
  51.     EditPaste,
  52.     EditClear
  53.     
  54. };
  55.  
  56. Error MyInitialiseApplication()
  57. {
  58.     return 0;
  59. }
  60.  
  61. void MyClearUpApplication()
  62. {
  63. }
  64.  
  65. void MySuspendApplication()
  66. {
  67.     if (frontWindow)
  68.         MyDeactivateWindow();
  69.             // this is needed if doesActivateOnFGSwitch build flag is on in target settings
  70. }
  71.  
  72. void MyResumeApplication()
  73. {
  74.     if (frontWindow)
  75.         MyActivateWindow();
  76.             // this is needed if doesActivateOnFGSwitch build flag is on in target settings
  77. }
  78.  
  79. void MyPerformIdleTasks()
  80. {
  81. #if Add_Threads_Support
  82.     ThreadsWork(appInFront ? 15 : 5);
  83.         // this lets threads work for 15/60ths second if application is in front or
  84.         // 5/60ths second if the application is not in front. Set as desired
  85. #endif
  86. }
  87.  
  88. void MyFreeUpMemory(Size spaceNeeded)
  89. {
  90. }
  91.  
  92. void MySetTheCursor(Point localPoint)
  93. {
  94.     SetCursor(&qd.arrow);
  95. }
  96.  
  97. void MyHandleKeyDown(char keyCharacter, EventRecord* event)
  98. {
  99.     Str255        windowTitle;
  100.  
  101.     if (frontWindow) { // some silly code to demonstrate key-presses
  102.         GetWTitle(frontWindow, windowTitle);
  103.         if (keyCharacter==0x08) {
  104.             if (*windowTitle)
  105.                 (*windowTitle)--;
  106.         } else
  107.             windowTitle[++*windowTitle]=(unsigned char)keyCharacter;
  108.         SetWTitle(frontWindow, windowTitle);
  109.     }
  110. }
  111.  
  112. void MyHandleMouseDown(Point localPoint, EventRecord* event)
  113. {
  114.     InvertRgn(frontWindow->visRgn);
  115.     while (StillDown())
  116.         {}
  117.     InvertRgn(frontWindow->visRgn);
  118. }
  119.  
  120. void MyCloseWindow()
  121. {
  122.     DisposeWindow(frontWindow);
  123. }
  124.  
  125. void MyActivateWindow()
  126. {
  127.     DrawGrowIcon(frontWindow);
  128. }
  129.  
  130. void MyDeactivateWindow()
  131. {
  132.     DrawGrowIcon(frontWindow);
  133. }
  134.  
  135. void MyResizeBounds(Rect* growLimits)
  136. {
  137.     SetRect(growLimits, 128, 64, qd.screenBits.bounds.right,
  138.         qd.screenBits.bounds.bottom);
  139. }
  140.  
  141. void MySizedWindow()
  142. {
  143.     InvalRgn(frontWindow->visRgn);
  144. }
  145.  
  146. void MyDrawWindow(WindowPtr drawWindow)
  147. {
  148.     EraseRgn(drawWindow->visRgn);
  149.     MoveTo(4, 16);
  150.     DrawString("\pThis is a bare shell of MADE");
  151.     DrawGrowIcon(drawWindow);
  152. }
  153.  
  154. void MyEnableMenus()
  155. {
  156.     SetMenuItemEnabled(129, 4, frontWindow!=0);
  157. }
  158.  
  159. void MyPerformMenu(long selection)
  160. {
  161.     Rect    windowRect;
  162.     
  163.     switch (selection) {
  164.         case FileNew:
  165.             SetRect(&windowRect, 48, 48, 256, 256);
  166.             NewWindow(0, &windowRect, "\pUntitled", true, zoomDocProc, (WindowPtr)-1, true, 0);
  167.             break;
  168.         
  169.         case FileClose:
  170.             MyCloseWindow();
  171.             frontWindow=0;
  172.                 // It is essential that this is done whenever the front window is closed,
  173.                 // otherwise it will seem to the rest of MADE that the window is still open
  174.             break;
  175.         
  176.         case FileQuit:
  177.             applicationHasQuit=true;
  178.             break;
  179.     }
  180. }
  181.  
  182. #if Use_AppleEvents
  183.     
  184. #if Handle_Open_Application_Event
  185. void MyOpenApplication()
  186. {
  187.     MyPerformMenu(FileNew);
  188. }
  189. #endif
  190.  
  191. #if Handle_Open_Documents_Event
  192. void MyOpenDocument(FSSpec* fileSpec)
  193. {
  194. }
  195. #endif
  196.  
  197. #if Handle_Print_Documents_Event
  198. void MyPrintDocument(FSSpec* fileSpec)
  199. {
  200. }
  201. #endif
  202.     
  203. #endif
  204.  
  205. #if Use_Drag_Manager
  206.  
  207. RgnHandle MyGetDragRegion(WindowPtr inWindow, Point localPoint, DragReference dragRef)
  208. {
  209.     RgnHandle    hiliteRgn;
  210.     
  211.     hiliteRgn=NewRgn();
  212.     CopyRgn(inWindow->visRgn, hiliteRgn);
  213.  
  214.     return hiliteRgn;
  215. }
  216.  
  217. Error MyReceiveDrag(WindowPtr inWindow, Point localPoint, DragReference dragRef)
  218. {
  219.     return dragNotAcceptedErr;
  220. }
  221.     
  222. #endif    
  223.  
  224. #if Support_Modeless_Dialogs
  225.  
  226. Boolean MyDialogFilter(DialogPtr theDialog, EventRecord* event, short *itemHit)
  227. {
  228.     char    keyCharacter;
  229.  
  230.     if (((event->what==keyDown) || (event->what==autoKey)) && (event->modifiers&cmdKey)) {
  231.             // Catch Command-Key menu equivalents
  232.         keyCharacter=(char)(event->message&charCodeMask);
  233.         MyEnableMenus();
  234.         SelectMenuItem(MenuKey(keyCharacter));
  235.         *itemHit=0; // Specify that no item has been hit
  236.         return true;
  237.     } else
  238.         return false;
  239. }
  240.  
  241. void MyHandleDialogEvent(EventRecord* event, DialogPtr theDialog, short itemHit)
  242. {
  243. }
  244.  
  245. #endif
  246.